

#include <stdio.h>
#include <fcntl.h>
#include <string.h>

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

#include <event2/event.h>

#define FIFO_NAME "/tmp/test.fifo"

void write_cb(evutil_socket_t fd, short waht, void *arg)
{
    static int num = 1;
    char buf[100] = {0};
    snprintf(buf, 100, "Hello World, %d\n", num++);
    write(fd, buf, strlen(buf));
}

int main(void)
{

    int fd = open(FIFO_NAME, O_WRONLY | O_NONBLOCK);

    struct event_base *base = event_base_new();

    struct event *ev = event_new(base, fd, EV_WRITE, write_cb, NULL);

    event_add(ev, NULL);

    event_base_dispatch(base);

    event_free(ev);
    event_base_free(base);
    close(fd);

    return 0;
}